
package com.bugly.bugdemo;
import java.lang.Thread.UncaughtExceptionHandler;

import com.tencent.bugly.crashreport.CrashReport;

import android.content.Context;
import android.util.Log;


public class CrashHandler implements UncaughtExceptionHandler{

	private Context mContext;
	private UncaughtExceptionHandler mDefaultHandler;

	/**
	 * 初始化
	 * 
	 * @param context
	 */
	public void init(Context context) {
		mContext = context;
		// 获取系统默认的UncaughtException处理器
		mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
		// 设置该CrashHandler为程序的默认处理器
		Thread.setDefaultUncaughtExceptionHandler(this);
		//nameString = BmobUserManager.getInstance(mContext).getCurrentUserName();
	}
	
	@Override
	public void uncaughtException(Thread thread, Throwable ex) {
		ex.printStackTrace();
		Log.e("hanshengjian", "异常",ex );
		CrashReport.postCatchedException(ex); 
		mDefaultHandler.uncaughtException(thread, ex);
	}

}

